(function () {
    return {
        import: [{
            url: "css/code.auto.css"
        }],
        data:{
            fieldList:[]
        },
        init:function(){
            this.data=this.params;
        },
        before:function(data){
            return  data;
        },
        after: function () {
            var _this = this;
            _this.$(".e-download").click(function () {
                if (!_this.$(".data-form").validate().form()) {
                    return;
                }
                var data = _this.toMap(".data-param");
                for (var i = 0; i < _this.data.fieldList.length; i++) {
                    _this.data.fieldList[i].descInfo = _this.$("#descInfo" + i).val();
                    _this.data.fieldList[i].type = _this.$("#type" + i).val();
                    _this.data.fieldList[i].column = _this.$("#column" + i).val();
                    _this.data.fieldList[i].name = _this.$("#name" + i).val();
                    _this.data.fieldList[i].desc = _this.$("#desc" + i).val();
                    _this.data.fieldList[i].selectFlag = _this.$("#selectFlag" + i).is(":checked");
                    _this.data.fieldList[i].addFlag = _this.$("#addFlag" + i).is(":checked");
                    _this.data.fieldList[i].updateFlag = _this.$("#updateFlag" + i).is(":checked");
                    _this.data.fieldList[i].defaultDateFlag = _this.$("#defaultDateFlag" + i).is(":checked");
                    _this.data.fieldList[i].notNullFlag = _this.$("#notNullFlag" + i).is(":checked");

                }

                for (var k in data) {
                    _this.data[k] = data[k];
                }
                var exportForm = $("<form target='_blank' action='" + window.api + "codeDownload/createCode' method='post' style='display: none'></form>")
                exportForm.append("<input type='hidden' name='token' value='" + window.sysUser.token + "'/>")
                exportForm.append("<input type='hidden' name='json' value='" + JSON.stringify(_this.data) + "'/>")
                $(document.body).append(exportForm);
                exportForm.submit();
                exportForm.remove();
            });

            _this.$(".e-download-key").click(function () {
                if (!_this.$(".data-form").validate().form()) {
                    return;
                }
                var data = _this.toMap(".data-param");
                for (var i = 0; i < _this.data.fieldList.length; i++) {
                    _this.data.fieldList[i].descInfo = _this.$("#descInfo" + i).val();
                    _this.data.fieldList[i].type = _this.$("#type" + i).val();
                    _this.data.fieldList[i].column = _this.$("#column" + i).val();
                    _this.data.fieldList[i].name = _this.$("#name" + i).val();
                    _this.data.fieldList[i].desc = _this.$("#desc" + i).val();
                    _this.data.fieldList[i].selectFlag = _this.$("#selectFlag" + i).is(":checked");
                    _this.data.fieldList[i].addFlag = _this.$("#addFlag" + i).is(":checked");
                    _this.data.fieldList[i].updateFlag = _this.$("#updateFlag" + i).is(":checked");
                    _this.data.fieldList[i].defaultDateFlag = _this.$("#defaultDateFlag" + i).is(":checked");
                    _this.data.fieldList[i].notNullFlag = _this.$("#notNullFlag" + i).is(":checked");

                }
                for (var k in data) {
                    _this.data[k] = data[k];
                }
                ajaxPost({
                    url: "codeDownload/createCodeKey", data: {"json": JSON.stringify(_this.data)}, success: function (data) {
                        swal({
                            title: "下载key",
                            text: data.data,
                            confirmButtonText:"确定"
                        });
                    }
                });
            });
        }
    }
});